<template>
<div id='denglu'>
    <div class="mainbody">
      <div class="manager">
       <el-button  icon="el-icon-user-solid" @click="register">注册</el-button>
      </div>
       <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="账号：">
        <el-input  v-model="form.username"  placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密码：">
        <el-input  v-model="form.password" placeholder="请输入密码" show-password></el-input>
        </el-form-item>
         <el-form-item>
          <el-button type="primary" @click="commit">用户登录</el-button>
          <!-- <el-button type="primary">管理员登录</el-button> -->
          </el-form-item>
      </el-form>
   </div>
</div>
</template>

<script>
export default {
  name: 'enter',
  data () {
    return {
      form: {
        username: '',
        password: ''
      },
      account: {
        username: '1',
        password: '1'
      }
    }
  },
  methods: {
    commit () {
      if (this.form.username !== '' && this.form.password !== '') {
        // this.$router.push('/home')
        let that = this
        this.$http({'userName': this.form.username, 'userPassword': this.form.password}, '/api/user/login').then(function (response) {
        // setState('enter/message', response.data.msg)
          console.log(response, '/////////')
          if (response.status === 200) {
            that.$message('登录成功,欢迎账号：' + that.form.username)
            that.$router.push('/main')
          }
        }).catch(function (response) {
        // that.$message('登录失败')
        })
        console.log('this.$store', this.$store.state.enter.message)
      } else {
        this.$message('账号密码不能为空')
      }
    },
    register () {
      this.$router.push('/register')
    }
  }
}
</script>

<style>
.mainbody{
  position: absolute;
  left: 50%;
  top: 50%;
  width: 350px;
  height: 240px;
  margin: -150px 0 0 -190px;
  padding: 20px 30px 30px 0px;
  border-radius: 5px;
  background: #fff;
}

.manager{
  padding: 0px 0px 20px 20px;
}
</style>
